Hệ thống quản lý phòng khám trực tuyến bằng PHP
1 <?php if(!defined('datalist_date_separator')) die('datalist.php not included!');
2
3 class DataCombo{
4 var $Query, // Only the first two fields of the query are used.
5 // The first field is treated as the primary key (data values),
6 // and the second field is the displayed data items.
7 $Class,
8 $Style,
9 $SelectName,
10 $FirstItem, // if not empty, the first item in the combo with value of ''
11 $SelectedData, // a value compared to first field value of the query to select
12 // an item from the combo.
13 $SelectedText,
14
15 $ListType, // 0: drop down combo, 1: list box, 2: radio buttons
16 $ListBoxHeight, // if ListType=1, this is the height of the list box
17 $RadiosPerLine, // if ListType=2, this is the number of options per line
18 $AllowNull,
19
20 $ItemCount, // this is returned. It indicates the number of items in the combo.
21 $HTML, // this is returned. The combo html source after calling Render().
22 $MatchText; // will store the parent caption value of the matching item.
23
24 function __construct(){ // PHP 7 compatibility
25 $this->DataCombo();
26 }
27
28 function DataCombo(){ // Constructor function
29 $this->FirstItem = '';
30 $this->HTML = '';
31 $this->Class = 'form-control Lookup';
32 $this->MatchText = '';
33 $this->ListType = 0;
34 $this->ListBoxHeight=10;
35 $this->RadiosPerLine=1;
36 $this->AllowNull=1;
37 }
38
39 function Render(){
40 global $Translation;
41
42 $eo['silentErrors']=true;
43 $result = sql($this->Query . ' limit ' . datalist_auto_complete_size, $eo);
44 if($eo['error']!=''){
45 $this->HTML = error_message(html_attr($eo['error']) . "\n\n<!--\n{$Translation['query:']}\n {$this->Query}\n-->\n\n");
46 return;
47 }
48
49 $this->ItemCount = db_num_rows($result);
50
51 $combo = new Combo();
52 $combo->Class = $this->Class;
53 $combo->Style = $this->Style;
54 $combo->SelectName = $this->SelectName;
55 $combo->SelectedData = $this->SelectedData;
56 $combo->SelectedText = $this->SelectedText;
57 $combo->SelectedClass = 'SelectedOption';
58 $combo->ListType = $this->ListType;
59 $combo->ListBoxHeight = $this->ListBoxHeight;
60 $combo->RadiosPerLine = $this->RadiosPerLine;
61 $combo->AllowNull = ($this->ListType == 2 ? 0 : $this->AllowNull);
62
63 while($row = db_fetch_row($result)){
64 $combo->ListData[] = html_attr($row[0]);
65 $combo->ListItem[] = $row[1];
66 }
67 $combo->Render();
68 $this->MatchText = $combo->MatchText;
69 $this->SelectedText = $combo->SelectedText;
70 $this->SelectedData = $combo->SelectedData;
71 if($this->ListType == 2){
72 $rnd = rand(100, 999);
73 $SelectedID = html_attr(urlencode($this->SelectedData));
74 $pt_perm = getTablePermissions($this->parent_table);
75 if($pt_perm['view'] || $pt_perm['edit']){
76 $this->HTML = str_replace(">{$this->MatchText}</label>", ">{$this->MatchText}</label> <button type=\"button\" class=\"btn btn-default view_parent hspacer-lg\" id=\"{$this->parent_table}_view_parent\" title=" . html_attr($Translation['View']) . "><i class=\"glyphicon glyphicon-eye-open\"></i></button>", $combo->HTML);
77 }
78 $this->HTML = str_replace(' type="radio" ', ' type="radio" onclick="' . $this->SelectName . '_changed();" ', $this->HTML);
79 }else{
80 $this->HTML = $combo->HTML;
81 }
82 }
83 }